package org.filecollector.filecontroller.virtualcatalogue.groupname;

import junit.framework.TestCase;
import org.junit.Before;
import org.junit.Test;

import java.util.Optional;

public class TestGroupName {

    @Before
    @Test
    public void TestConstruct() {
        var check = new GroupNameClass(0L, (byte) 64);
        TestCase.assertEquals(0L, check.getMinId().longValue());
        TestCase.assertEquals(Long.MAX_VALUE, check.getMaxId().longValue());
        check = new GroupNameClass(0xF0L, (byte) 4);
        TestCase.assertEquals(0xF0L, check.getMinId().longValue());
        TestCase.assertEquals(0xFFL, check.getMaxId().longValue());
        check = new GroupNameClass(0xF3L, (byte) 4);
        TestCase.assertEquals(0xF0L, check.getMinId().longValue());
        TestCase.assertEquals(0xFFL, check.getMaxId().longValue());
    }

    @Test
    public void testCheckingNames() {
        TestCase.assertTrue(GroupNameFactory.isCorrect("FFFM63"));
        TestCase.assertTrue(GroupNameFactory.isCorrect("2415415M60"));
        TestCase.assertTrue(GroupNameFactory.isCorrect("1111M6"));
        TestCase.assertTrue(GroupNameFactory.isCorrect("2456M3"));
        TestCase.assertTrue(GroupNameFactory.isCorrect("142646M36"));
        TestCase.assertFalse(GroupNameFactory.isCorrect("f895M5"));
        TestCase.assertFalse(GroupNameFactory.isCorrect("F895M65"));
        TestCase.assertFalse(GroupNameFactory.isCorrect("2895MF"));
        TestCase.assertFalse(GroupNameFactory.isCorrect("95M222"));
        TestCase.assertFalse(GroupNameFactory.isCorrect("FFFFFFFFFFFFFFFFM5"));
        TestCase.assertFalse(GroupNameFactory.isCorrect("8000000000000000M5"));
        TestCase.assertFalse(GroupNameFactory.isCorrect("FFFFFFFFFFFFFFFFFM5"));
    }

    @Test
    public void testFactoryMethod() {
        TestCase.assertEquals(
                new GroupNameClass(0x552L, (byte) 6),
                GroupNameFactory.getGroupNameByString("552M6").get()
        );
        TestCase.assertEquals(
                new GroupNameClass(0x552FL, (byte) 64),
                GroupNameFactory.getGroupNameByString("552FM64").get()
        );
        TestCase.assertEquals(
                new GroupNameClass(0x52A52L, (byte) 16),
                GroupNameFactory.getGroupNameByString("52A52M16").get()
        );
        TestCase.assertEquals(
                new GroupNameClass(0x51C52L, (byte) 5),
                GroupNameFactory.getGroupNameByString("51C52M5").get()
        );
        TestCase.assertEquals(
                new GroupNameClass(0x55ABC2L, (byte) 6),
                GroupNameFactory.getGroupNameByString("55ABC2M6").get()
        );
        TestCase.assertEquals(
                Optional.empty(),
                GroupNameFactory.getGroupNameByString("414RM2")
        );
        TestCase.assertEquals(
                Optional.empty(),
                GroupNameFactory.getGroupNameByString("4142")
        );
        TestCase.assertEquals(
                Optional.empty(),
                GroupNameFactory.getGroupNameByString("414M124")
        );
        TestCase.assertEquals(
                Optional.empty(),
                GroupNameFactory.getGroupNameByString("AAaM52")
        );
    }
}
